#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <Windows.h>

void PrintFirstImage(void)
{
    printf("--myboundary\n");
    printf("Content-Type: image/jpg\n\n");

    FILE * img = fopen("../images/slide_show/1.jpg", "rb");
    int i = 0;
    while (!feof(img))
    {
        i = fgetc(img);
        putchar(i);
    }
    fclose(img);
    Sleep(3000);
}

void PrintSecondImage(void)
{
    printf("--myboundary\n");
    printf("Content-Type: image/jpg\n\n");

    FILE * img = fopen("../images/slide_show/2.jpg", "rb");
    int i = 0;
    while (!feof(img))
    {
        i = fgetc(img);
        putchar(i);
    }
    fclose(img);
    Sleep(3000);
}

void PrintThirdImage(void)
{
    printf("--myboundary\n");
    printf("Content-Type: image/jpg\n\n");

    FILE * img = fopen("../images/slide_show/3.jpg", "rb");
    int i = 0;
    while (!feof(img))
    {
        i = fgetc(img);
        putchar(i);
    }
    fclose(img);
    Sleep(3000);
}

void main(void)
{
    int res = _setmode( _fileno( stdout ), _O_BINARY); 
    if (res == -1)
    {
        perror("Cannot set mode");
    }
    
    printf("Content-Type: multipart/x-mixed-replace;boundary=myboundary\n\n");

    PrintFirstImage();
    PrintSecondImage();
    PrintThirdImage();

    printf("\n--myboundary--\n");
}